/**
 * 
 */
package registnet.courseDemand;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import registnet.dao.ClassroomView;
import registnet.dao.CourseView;
import registnet.dao.SectionLaboratory;
import registnet.dao.SectionLecture;

/**
 * A utility class for this project. Contains methods for sorting lists
 * 
 * @author Dexter Ryan Carrasco
 */
public class CourseDemandUtility {

	/**
	 * Sorts ascendingly the rooms according to their capacity
	 * 
	 * @param rooms
	 * @return
	 */
	public static List<ClassroomView> sortClassroomsByCapacity(
			final List<ClassroomView> rooms) {
		Collections.sort(rooms, new Comparator<ClassroomView>() {
			public int compare(final ClassroomView room1,
					final ClassroomView room2) {

				return room1.getCapacity() - room2.getCapacity();
			}
		});

		return rooms;
	}

	/**
	 * Sorts the list of student clusters according to the number of students it
	 * have (size)
	 * 
	 * @param studentClusters
	 * @return
	 */
	public static List<StudentCluster> sortClustersBySize(
			final List<StudentCluster> studentClusters) {
		Collections.sort(studentClusters, new Comparator<StudentCluster>() {
			public int compare(final StudentCluster cluster1,
					final StudentCluster cluster2) {
				return cluster2.size() - cluster1.size();
			}
		});

		return studentClusters;
	}

	/**
	 * Sorts the courses according to the descending number of students needing
	 * the course
	 * 
	 * @param coursesList
	 * @return
	 */
	public static List<CourseView> sortCoursesByDescendingSize(
			final List<CourseView> coursesList) {
		Collections.sort(coursesList, new Comparator<CourseView>() {
			public int compare(final CourseView course1,
					final CourseView course2) {
				return course2.getRecommendedTo() - course1.getRecommendedTo();
			}
		});

		return coursesList;
	}

	/**
	 * Sorts the list of laboratory according to their sections
	 * 
	 * @param labSections
	 * @return sorted list
	 */
	public static List<SectionLaboratory> sortLabSections(
			final List<SectionLaboratory> labSections) {
		Collections.sort(labSections, new Comparator<SectionLaboratory>() {
			public int compare(final SectionLaboratory lab1,
					final SectionLaboratory lab2) {

				int value1, value2;

				if (lab1.getDaysInt() == null || lab1.getTimeInt() == null) {
					value1 = 800;
				} else {
					value1 = lab1.getDaysInt().get(0) * 100
							+ lab1.getTimeInt()[0];
				}

				if (lab2.getDaysInt() == null || lab2.getTimeInt() == null) {
					value2 = 800;
				} else {
					value2 = lab2.getDaysInt().get(0) * 100
							+ lab2.getTimeInt()[0];
				}

				return value1 - value2;
			}
		});

		return labSections;
	}

	/**
	 * Sorts the list of lecture according to their sections
	 * 
	 * @param lectureSections
	 * @return sorted List
	 */
	public static List<SectionLecture> sortLectureSections(
			final List<SectionLecture> lectureSections) {
		Collections.sort(lectureSections, new Comparator<SectionLecture>() {
			public int compare(final SectionLecture lecture1,
					final SectionLecture lecture2) {

				int value1, value2;

				if (lecture1.getDaysInt() == null
						|| lecture1.getTimeInt() == null) {
					value1 = 800;
				} else {
					value1 = lecture1.getDaysInt().get(0) * 100
							+ lecture1.getTimeInt()[0];
				}

				if (lecture2.getDaysInt() == null
						|| lecture2.getTimeInt() == null) {
					value2 = 800;
				} else {
					value2 = lecture2.getDaysInt().get(0) * 100
							+ lecture2.getTimeInt()[0];
				}

				return value1 - value2;
			}
		});

		return lectureSections;
	}

}
